﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Pomodoro.Oob.Controls
{
    public partial class ControlBar : UserControl
    {
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Title.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TitleProperty =
            DependencyProperty.Register("Title", typeof(string), typeof(ControlBar), new PropertyMetadata(string.Empty));


        public ControlBar()
        {
            InitializeComponent();

            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                this.Visibility = Visibility.Visible;
            }
            else
            {
                if (App.IsRunningOOBWithPermission)
                {
                    this.Visibility = Visibility.Visible;
                    this.minButton.Click += cnvMinimizeButton_MouseLeftButtonDown;
                    this.closeButton.Click += cnvCloseButton_MouseLeftButtonDown;
                    this.MouseLeftButtonDown += ControlBar_MouseLeftButtonDown;
                }
                else
                {
                    this.Visibility = Visibility.Collapsed;
                }
            }
        }

        void ControlBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            App.Current.MainWindow.DragMove();
        }

        void cnvCloseButton_MouseLeftButtonDown(object sender, RoutedEventArgs routedEventArgs)
        {
            App.Current.MainWindow.Close();
        }

        void cnvMinimizeButton_MouseLeftButtonDown(object sender, RoutedEventArgs routedEventArgs)
        {
            App.Current.MainWindow.WindowState = WindowState.Minimized;
        }
    }
}
